﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BOSS.Framework.Search.UrlBuilder;
using BOSS.Framework.Search.ValueProvider;

namespace BOSS.Framework.Search.Context
{
    /// <summary>
    /// 搜索上下文接口
    /// </summary>
    public interface ISearchContext
    {
        /// <summary>
        /// 获取 内容类型
        /// </summary>
        string ContentType { get; }

        /// <summary>
        /// 获取 过滤参数部分的长度
        /// </summary>
        int FilterCount { get; }

        /// <summary>
        /// 获取 过滤参数部分
        /// </summary>
        IEnumerable<IFilterPart> Filters { get; }

        /// <summary>
        /// 获取 是否只允许一个排序参数
        /// </summary>
        bool OneSortOnly { get; }

        /// <summary>
        /// 获取 排序参数部分的长度
        /// </summary>
        int SortCount { get; }

        /// <summary>
        /// 获取 排序参数部分
        /// </summary>
        IEnumerable<ISortPart> Sorts { get; }

        /// <summary>
        /// 获取 分页大小
        /// </summary>
        int PageSize { get; }

        /// <summary>
        /// 获取 当前页序号，下标从 1 开始
        /// </summary>
        int PageIndex { get; }

        /// <summary>
        /// 获取 URL 构造器工厂
        /// </summary>
        IUrlBuilderFactory UrlBuilderFactory { get; }

        /// <summary>
        /// 获取 默认值提供器
        /// </summary>
        IDefaultValueProvider DefaultValueProvider { get; }

        /// <summary>
        /// 设置筛选部分
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        void SetFilter(string fieldName, string value);

        /// <summary>
        /// 设置筛选部分
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        void SetFilter(string fieldName, decimal value);

        /// <summary>
        /// 设置筛选部分
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        void SetFilter(string fieldName, int value);

        /// <summary>
        /// 设置筛选部分
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        void SetFilter(string fieldName, bool value);

        /// <summary>
        /// 设置筛选部分
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="minValue"></param>
        /// <param name="includeMinValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="includeMaxValue"></param>
        void SetFilter(string fieldName, DateTime minValue, bool includeMinValue, DateTime maxValue, bool includeMaxValue);

        /// <summary>
        /// 设置筛选部分
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="minValue"></param>
        /// <param name="includeMinValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="includeMaxValue"></param>
        void SetFilter(string fieldName, decimal minValue, bool includeMinValue, decimal maxValue, bool includeMaxValue);

        /// <summary>
        /// 设置筛选部分
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="minValue"></param>
        /// <param name="includeMinValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="includeMaxValue"></param>
        void SetFilter(string fieldName, int minValue, bool includeMinValue, int maxValue, bool includeMaxValue);

        /// <summary>
        /// 移除筛选部份
        /// </summary>
        /// <param name="fieldName"></param>
        void RemoveFilter(string fieldName);

        /// <summary>
        /// 设置排序部分
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="descend"></param>
        void SetSort(string fieldName, bool descend);

        /// <summary>
        /// 设置分页大小
        /// </summary>
        /// <param name="pageSize"></param>
        void SetPageSize(int pageSize);

        /// <summary>
        /// 设置页序号
        /// </summary>
        /// <param name="pageIndex"></param>
        void SetPageIndex(int pageIndex);

        /// <summary>
        /// 构造 URL
        /// </summary>
        /// <returns></returns>
        string BuildUrl();

        /// <summary>
        /// 构造 URL
        /// </summary>
        /// <param name="urlBuilder"></param>
        /// <returns></returns>
        string BuildUrl(IUrlBuilder urlBuilder);

        /// <summary>
        /// 根据新的筛选部分预取 URL，同时页序号被重置为初始值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        string PrefetchNewFilterUrl(string fieldName, string value);

        /// <summary>
        /// 根据新的筛选部分预取 URL，同时页序号被重置为初始值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        string PrefetchNewFilterUrl(string fieldName, decimal value);

        /// <summary>
        /// 根据新的筛选部分预取 URL，同时页序号被重置为初始值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        string PrefetchNewFilterUrl(string fieldName, int value);

        /// <summary>
        /// 根据新的筛选部分预取 URL，同时页序号被重置为初始值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        string PrefetchNewFilterUrl(string fieldName, bool value);

        /// <summary>
        /// 根据新的筛选部分预取 URL，同时页序号被重置为初始值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="minValue"></param>
        /// <param name="includeMinValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="includeMaxValue"></param>
        /// <returns></returns>
        string PrefetchNewFilterUrl(string fieldName, DateTime minValue, bool includeMinValue, DateTime maxValue, bool includeMaxValue);

        /// <summary>
        /// 根据新的筛选部分预取 URL，同时页序号被重置为初始值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="minValue"></param>
        /// <param name="includeMinValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="includeMaxValue"></param>
        /// <returns></returns>
        string PrefetchNewFilterUrl(string fieldName, decimal minValue, bool includeMinValue, decimal maxValue, bool includeMaxValue);

        /// <summary>
        /// 根据新的筛选部分预取 URL，同时页序号被重置为初始值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="minValue"></param>
        /// <param name="includeMinValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="includeMaxValue"></param>
        /// <returns></returns>
        string PrefetchNewFilterUrl(string fieldName, int minValue, bool includeMinValue, int maxValue, bool includeMaxValue);

        /// <summary>
        /// 根据新的排序部分预取 URL，同时页序号被重置为初始值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="descend"></param>
        /// <returns></returns>
        string PrefetchNewSortUrl(string fieldName, bool descend);

        /// <summary>
        /// 根据新的排序部分预取 URL，同时页序号被重置为初始值。如果指定的字段为当前所使用的排序字段，则反转之
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="descendAsDefault"></param>
        /// <returns></returns>
        string PrefetchNewToggleSortUrl(string fieldName, bool descendAsDefault);

        /// <summary>
        /// 根据新的页序号预取 URL
        /// </summary>
        /// <param name="absoluteIndex">是否使用绝对值</param>
        /// <param name="value">如果使用绝对值，则为新的页序号；否则为相对当前页的差值</param>
        /// <returns></returns>
        string PrefetchNewPageIndexUrl(bool absoluteIndex, int value);

        /// <summary>
        /// 获取过滤条件的布尔值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        bool? GetFilterTermValueAsBoolean(string fieldName);

        /// <summary>
        /// 获取过滤条件的整数值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        int? GetFilterTermValueAsInt32(string fieldName);

        /// <summary>
        /// 获取过滤条件的整数值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        decimal? GetFilterTermValueAsDecimal(string fieldName);

        /// <summary>
        /// 获取过滤条件的字符串值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        string GetFilterTermValueAsString(string fieldName);

        /// <summary>
        /// 获取过滤条件的格式化后的字符串值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        string GetFilterTermValueAsString(string fieldName, string format);

        /// <summary>
        /// 获取范围过滤条件的最小整数值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        int? GetFilterRangeMinValueAsInt32(string fieldName);

        /// <summary>
        /// 获取范围过滤条件的最大整数值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        int? GetFilterRangeMaxValueAsInt32(string fieldName);

        /// <summary>
        /// 获取范围过滤条件的最小数值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        decimal? GetFilterRangeMinValueAsDecimal(string fieldName);

        /// <summary>
        /// 获取范围过滤条件的最大数值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        decimal? GetFilterRangeMaxValueAsDecimal(string fieldName);

        /// <summary>
        /// 获取范围查询条件的最小日期值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        DateTime? GetFilterRangeMinValueAsDateTime(string fieldName);

        /// <summary>
        /// 获取范围过滤条件的最大日期值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        DateTime? GetFilterRangeMaxValueAsDateTime(string fieldName);
    }
}
